package com.homework;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CompletableFuture02 {
    public static void main(String[] args) throws Exception {
        long start = System.currentTimeMillis();

        System.out.println("Main Thread Start!");

        ExecutorService executorService = Executors.newCachedThreadPool();
        CompletableFuture<String> cf = new CompletableFuture<String>();

        executorService.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(1000L);
                cf.complete("123456");
                return null;
            }
        });

        System.out.println("异步处理结果为：" + cf.get());

        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");

        executorService.shutdown();
        System.out.println("Main Thread End!");
    }
}
